package com.example.day_0813_103.slice;

import com.example.day_0813_103.ResourceTable;
import com.example.day_0813_103.Two_Ability;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.hiviewdfx.HiLog;
import ohos.hiviewdfx.HiLogLabel;


public class MainAbilitySlice extends AbilitySlice {

    private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP,0x00201,"MY_TAG");

    private Button button;
    @Override
    public void onStart(Intent intent) {
        HiLog.info(LABEL,"这里是 MainAbilitySlice 的 onStart");
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        findComponentById(ResourceTable.Id_main_id)
                .setClickedListener(com -> myAblit("com.example.day_0813_103.Two_Ability"));
        // 跳转到 Six_AbilitySlice
        findComponentById(ResourceTable.Id_main_btn_two)
                .setClickedListener(component -> sixSlice("com.example.day_0813_103.Six_Ability"));
    }
    private void sixSlice(String abilityName) {
        Intent it = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName("com.example.day_0813_103")
                .withAbilityName(abilityName)
                .build();
        it.setOperation(operation);
        startAbility(it);
    }
    private void myAblit(String abilityName) {
        Intent it = new Intent();
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName("com.example.day_0813_103")
                .withAbilityName(abilityName)
                .build();
        it.setOperation(operation);
        startAbilityForResult(it,123);
    }


    @Override
    public void onActive() {
        HiLog.info(LABEL,"这里是 MainAbilitySlice 的 onActive");
        super.onActive();
    }
    @Override
    protected void onInactive() {
        HiLog.info(LABEL,"这里是 MainAbilitySlice 的 onInactive");
        super.onInactive();
    }

    @Override
    protected void onBackground() {
        HiLog.info(LABEL,"这里是 MainAbilitySlice 的 onBackground");
        super.onBackground();
    }
    @Override
    public void onForeground(Intent intent) {
        HiLog.info(LABEL,"这里是 MainAbilitySlice 的 onForeground");
        super.onForeground(intent);
    }

    @Override
    protected void onStop() {
        HiLog.info(LABEL,"这里是 MainAbilitySlice 的 onStop");
        super.onStop();
    }
}
